package ru.vsu.cs.brainsaver.game;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DrawFilter;
import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.util.AttributeSet;

public class BrainSaverGame extends ArcadeGame{
	public static final String NAME="BrainSaver";

	public static final long UPDATE_DELAY=40;
	
	private Context mContext;
	
	private Paint cPaint;
		
	private Bitmap brain;
	private Bitmap zombi1;
	private Zombie z1;
	private Brain b;
		
	public BrainSaverGame(Context context)
	{
		super(context);
		mContext=context;
		super.setUpdatePeriod(UPDATE_DELAY);
	}
	
	public BrainSaverGame(Context context,AttributeSet attr)
	{
		super(context,attr);
		mContext=context;
		super.setUpdatePeriod(UPDATE_DELAY);
	}
	
	public void initialize()
	{
		b=new Brain();
		z1=new Zombie();
		setBackgroundResource(R.drawable.background);
		cPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		cPaint.setStyle(Paint.Style.STROKE);
		cPaint.setColor(Color.LTGRAY);
				
		brain = getImage(R.drawable.brain);
		zombi1 = getImage(R.drawable.zombie1);
			
		b.init(brain, this.getWidth()/2-brain.getWidth()/2 ,this.getHeight()-getHeight()/2);
		z1.init(zombi1, b,this.getHeight());		
	}

	@Override
	protected void onDraw(Canvas canvas)
	{		
		b.Draw(canvas,cPaint);
		z1.Draw(canvas,cPaint);	
	}
	
	@Override
	protected void updatePhysics() 
	{		
		//b.Update();
		z1.Update(this.getWidth()/2-brain.getWidth()/2 ,this.getHeight()-getHeight()/2,this.getWidth()/2-brain.getWidth()/2+brain.getWidth() ,this.getHeight()-getHeight()/2+brain.getHeight());	
	}

	@Override
	protected boolean gameOver() 
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	protected long getScore() 
	{
		// TODO Auto-generated method stub
		return 0;
	}
	
	/*@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) 
	{
		keyUp(keyCode);
		return true;
	}
	
	public boolean onTouchEvent(MotionEvent event) {
		int tx = (int)event.getX();
		int ty = (int)event.getY();
		// Has the ship been touched. if so move it
		if ( tx >= x && tx <= x + ship.getWidth()
		&& ty >= y && ty <= y + ship.getHeight()){
		x = tx - (ship.getWidth()/2);
		y = ty - (ship.getHeight()/2);
		}
		// else handle tap
		else if ( event.getAction() == MotionEvent.ACTION_UP)
		{// if not in game, start
			if ( !ingame ) {
				ingame = true;
				GameStart();
				}
				else {
				// fire gun
				keyDown(KeyEvent.KEYCODE_SPACE);
				}
				}
				return true;
				}
	public boolean keyDown( int key) {
		if (ingame) {
		mousex = -1;
		if (key == KeyEvent.KEYCODE_DPAD_LEFT
		|| key == KeyEvent.KEYCODE_Q)
		dx = -1;
		if (key == KeyEvent.KEYCODE_DPAD_RIGHT
		|| key == KeyEvent.KEYCODE_W)
		dx = 1;
		if (key == KeyEvent.KEYCODE_DPAD_UP
		|| key == KeyEvent.KEYCODE_O)
		dy = -1;
		if (key == KeyEvent.KEYCODE_DPAD_DOWN
		|| key == KeyEvent.KEYCODE_L)
		dy = 1;
		if ( (key == KeyEvent.KEYCODE_SPACE) ) {
		if (bcur > 0) {
		fireGun();
		}
		}
		} else {
		if (key == KeyEvent.KEYCODE_S) {
		ingame = true;
		GameStart();
		}
		}
		if (key == KeyEvent.KEYCODE_E){
		ingame = false;
		}
		if (key == KeyEvent.KEYCODE_Q){
		// Arggg!! There should be a better wayt to quit!
		System.exit(0);
		}
		return true;
		}
		
		public boolean keyUp(int key) {
		if (key == KeyEvent.KEYCODE_DPAD_LEFT
		|| key == KeyEvent.KEYCODE_DPAD_RIGHT
		|| key == KeyEvent.KEYCODE_Q
		|| key == KeyEvent.KEYCODE_W)
		dx = 0;
		if (key == KeyEvent.KEYCODE_DPAD_UP
		|| key == KeyEvent.KEYCODE_DPAD_DOWN
		|| key == KeyEvent.KEYCODE_O
		|| key == KeyEvent.KEYCODE_L)
		dy = 0;
		return true;
		}
	*/
}
